package top.malaoshi.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {

    //连接数据库
    public static Connection connect(String driver,String url,String username,String password) throws ClassNotFoundException, SQLException {
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, username, password);

        return connection;
    }


    //连接数据库，可以指定是否自动提交
    public static Connection connect(String driver,String url,String username,String password,boolean autoCommit) throws ClassNotFoundException, SQLException{
        Connection connection = connect(driver, url, username, password);
        //设置是否自动提交
        connection.setAutoCommit(autoCommit);
        return connection;
    }

}
